var app=getApp();
Component({

  /**
   * 组件的属性列表
   */
  properties: {
    id:{
      "type":String
    },
    item:{
      "type":Object,
      "value":{
        nickName:"默认用户",
        rating:4,
        isShow:1,
        showAction:"展示中",
        commentText:"好",
        commentDate:"2024-01-01",
        foodName:"默认菜名",
        canteenName:"默认饭堂"
      }

    }
  },

  /**
   * 组件的初始数据
   */
  data: {

  },

  /**
   * 组件的方法列表
   */
  methods: {
    delComment(){
      wx.showModal({
        title: '再次确认',
        content: '是否删除该评论',
        complete: (res) => {
          if (res.cancel) {
            
          }
      
          if (res.confirm) {
            wx.request({
              url: app.globalData.apiUrl+'/comment/deleteCommentByCommentId',
              method:"POST",
              data:{
                "token":wx.getStorageSync('token'),
                "commentID":parseInt(this.id)
              },
              success:(res)=>{
                console.log(res);
                this.triggerEvent("reLoadComment")
              }
            })
          }

        }
      })

    },
    notShowComment(){
      wx.request({
        url: app.globalData.apiUrl+'/comment/commentIsShow',
        method:"POST",
        data:{
          "token":wx.getStorageSync('token'),
          "commentID":parseInt(this.id),
          "isShow":0
        },
        success:(res)=>{
          console.log(res);
          wx.showToast({
            title: '评论隐藏成功',
          })
          this.upDate();
        }
      })
    },
    isShowComment(){
      wx.request({
        url: app.globalData.apiUrl+'/comment/commentIsShow',
        method:"POST",
        data:{
          "token":wx.getStorageSync('token'),
          "commentID":parseInt(this.id),
          "isShow":1
        },
        success:(res)=>{
          console.log(res);
          wx.showToast({
            title: '评论显示成功',
          })
          this.upDate();
        }
      });
      
    },
    upDate(){
      this.triggerEvent('upDateFar');
    }
  }
})